package com.joe.learn.socket;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.Socket;

//客户端代码
public class SocketClient {

    private static final Logger logger = LoggerFactory.getLogger(SocketClient.class);

    public static void main(String[] args) throws IOException {

        //获取连接
        Socket socket = new Socket("localhost", 9000); //向服务端发送数据

        socket.getOutputStream().write("HelloServer".getBytes());
        socket.getOutputStream().flush();
        logger.info("向服务端发送数据结束");
        byte[] bytes = new byte[1024];
        socket.getInputStream().read(bytes);
        logger.info("接收到服务端的数据:" + new String(bytes));
        socket.close();
    }
}


